home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / recent2 / manmaker12.lha / ManMaker / man.c < prev    next >
C/C++ Source or Header  |  1997-06-10  |  2KB  |  121 lines

  1.  
  2. /* man.c
  3.  *
  4.  * Man pages on amiga?
  5.  *
  6.  * by Mark Papadakis, markp@palamida.math.uch.gr
  7.  * http://palamida.math.uch.gr/markp
  8.  *
  9.  * -- changes --
  10.  * 10.06.07 : New options, read MANPATH env variable now
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <dos/dos.h>
  17. #include <proto/dos.h>
  18. #include <exec/types.h>
  19.  
  20. #define VERSION "1.2"
  21. const UBYTE Version[] = "$VER: man "VERSION" by MarkP (10.06.97)\n\n";
  22. int main(int argc, char *argv[])
  23. {   
  24.     FILE *envFile = NULL;
  25.     char tbuf[256];
  26.     char ndir[20][128];
  27.     int ndirs = 0;
  28.     char full[256];
  29.     char command[512];
  30.     BPTR tlock = NULL;
  31.     int i;
  32.     int found = 0;
  33.     int search_mode = 0;
  34.     if(argc<2)
  35.     {
  36.     fprintf(stderr,"Syntax : Man [-k] <function>\n");
  37.     exit(1L);
  38.     }
  39.     if(argv[1][0]=='?')
  40.     {
  41.     printf("man version "VERSION" by MarkP(Mark Papadakis).\n");
  42.     printf("Reads man pages. Can also look for keywords using the -k option.\n");
  43.     printf("Read the docs for further info.\n");
  44.     exit(0);
  45.     }
  46.  
  47.     ndirs = 0;
  48.     envFile = fopen("ENV:MANPATH","r");
  49.     if(!envFile)
  50.     {
  51.     ndirs = 1;
  52.     strcpy(&ndir[1][0],"ManDir:");
  53.     }
  54.     else
  55.     {
  56.     while(fgets(tbuf,254, envFile))
  57.     {
  58.         if(tbuf[0]>32 && tbuf[0]!='#')
  59.         {
  60.         int l;
  61.         l = strlen(tbuf);
  62.         if(tbuf[l-1]=='\n')
  63.             tbuf[l-1]='\0';
  64.         ndirs++;
  65.         l = strlen(tbuf);
  66.         if(tbuf[l-1]!='/' && tbuf[l-1]!=':')
  67.               strcat(tbuf,"/");
  68.         strcpy(&ndir[ndirs][0], tbuf);
  69.          }
  70.      }
  71.      fclose(envFile);
  72.     }
  73.  
  74.  
  75.     // search directories
  76.     for(i = 1; i<=ndirs;i++)
  77.     {
  78.  
  79.  
  80.     if(!(strcmp(argv[1],"-k")))
  81.     {
  82.     // man -k function
  83.     if(argc<=2)
  84.     {
  85.         printf("Error : syntax man -k what?\nwhat not defined.\n");
  86.         exit(1L);
  87.     }
  88.     sprintf(full,"Search %s %s QUIET", &ndir[i][0], argv[2]);
  89.     system(full);
  90.     search_mode = 1;
  91.     }
  92.     else
  93.     {
  94.     // man function
  95.     sprintf(full,"%s%s",&ndir[i][0],argv[1]);
  96.     tlock = Lock(full,ACCESS_READ);
  97.     if(!tlock)
  98.           strcat(full,"A");
  99.     else
  100.           UnLock(tlock);
  101.  
  102.        tlock = Lock(full,ACCESS_READ);
  103.        if(tlock)
  104.        {
  105.        UnLock(tlock);
  106.        found = 1;
  107.        sprintf(command,"more %s",full);
  108.        system(command);
  109.        exit(0);
  110.        }
  111.     }
  112.  
  113.     }
  114.  
  115.     if(!found && !search_mode)
  116.        printf("'%s' not found.\n",argv[1]);
  117. }
  118.     
  119.  
  120.     
  121.